import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by sunil.kalva@mkhoj.com.
 * User: sunil.kalva
 * Date: May 11, 2010
 */
public class Regex {

    public static void main(String[] args) {

//        String imgRegex = "<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>";
//        String bod = "<img src=\"http://www.kk.org/cooltools/popper-sm.jpg\" /><p>My Aunt Lee bought several of these popcorn poppers and gave them away as Christmas presents over 20 years ago and I am so happy with the one I received that I still use it today. </p>\n" +
//                "\n" +
//                "<p>It makes the best tasting popcorn with very few \"old maids\" in minutes. Put just a splash of oil in it, add a couple of kernels of corn, turn the stove to Med-High, wait for the few Kernels to pop, add a half cup of popping corn and turn the handle. They seem really cheap because they are made from very thin walled aluminum but that's why they work so well as they transfer the heat instantly.</p>\n" +
//                "\n" +
//                "<p>You get light, fluffy, wonderful popcorn every time and virtually all of it pops. I can make a batch of popcorn during a commercial break and never miss a beat. You use very little oil so it's better for you than that microwave stuff and tastes much better than an air popped batch.</p>\n" +
//                "\n" +
//                "<p>If you enjoy fresh popcorn, the Whirley-Pop Theater Stovetop Popcorn Popper is the best way to make it.</p> -- Mark Wialbut<p>Whirley-Pop Theater Stovetop Popcorn Popper<br />\n" +
//                "$22</p><p>Available from <a href=\"http://www.amazon.com/exec/obidos/ASIN/B00004SU35/ref=nosim/kkorg-20\">Amazon</a></p><p>Manufactured by <a href=\"http://www.wabashvalleyfarms.com/\">Wabash Valley Farms</a></p>";
//
//        Pattern p = null;
//        Matcher m = null;
//
//        String word0 = null;
//        p = Pattern.compile(".*<img[^>]*src=\"([^\"]*)", Pattern.CASE_INSENSITIVE);
//        m = p.matcher(bod);
//        while(m.find()) {
//            word0 = m.group(1);
//            System.out.println(word0);
//        }

        String description = "<img src=\"http://www.kk.org/cooltools/popper-sm.jpg\" />  <p>My Aunt Lee bought several of these popcorn poppers and gave them away as Christmas presents over 20 years ago and I am so happy with the one I received that I still use it today. </p>\n" +
                "\n" +
                "<p>It makes the best tasting popcorn with very few \"old maids\" in minutes. Put just a splash of oil in it, add a couple of kernels of corn, turn the stove to Med-High, wait for the few Kernels to pop, add a half cup of popping corn and turn the handle. They seem really cheap because they are made from very thin walled aluminum but that's why they work so well as they transfer the heat instantly.</p>\n" +
                "\n" +
                "<p>You get light, fluffy, wonderful popcorn every time and virtually all of it pops. I can make a batch of popcorn during a commercial break and never miss a beat. You use very little oil so it's better for you than that microwave stuff and tastes much better than an air popped batch.</p>\n" +
                "\n" +
                "<p>If you enjoy fresh popcorn, the Whirley-Pop Theater Stovetop Popcorn Popper is the best way to make it.</p>\n" +
                "-- Mark Wialbut\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "<p>Whirley-Pop Theater Stovetop Popcorn Popper<br />\n" +
                "$22</p>\n" +
                "\n" +
                "\n" +
                "\n" +
                "<p>Available from <a href=\"http://www.amazon.com/exec/obidos/ASIN/B00004SU35/ref=nosim/kkorg-20\">Amazon</a></p>\n" +
                "\n" +
                "\n" +
                "\n" +
                "<p>Manufactured by <a href=\"http://www.wabashvalleyfarms.com/\">Wabash Valley Farms</a></p> \n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "";
//        description = description.replaceAll("\\n ","g");
//        description = description.replaceAll("   ","");
//        System.out.println(description);

        String patternStr = "(?m)$^|[\\r\\n]+\\z";
        String replaceStr = " ";
        Pattern pattern = Pattern.compile(patternStr);
        Matcher matcher = pattern.matcher(description);
        description = matcher.replaceAll(replaceStr);
        System.out.println(description);
    }
}
